/*
 * $Id: RecordDeviceImpl.java,v \$Revision$
 *
 * Copyright (c) Critical Software S.A., All Rights Reserved.
 * (www.criticalsoftware.com)
 *
 * This software is the proprietary information of Critical Software S.A.
 * Use is subject to license terms.
 *
 * Last changed on: $Date: \$Date$
 * Last changed by: $Author: trsimoes $
 */
package org.eden.karb.device.audio.impl;

import org.eden.karb.device.RecordDevice;

import java.io.ByteArrayOutputStream;

/**
 * Audio recording device implementation.
 *
 * @author trsimoes
 */
public class AudioRecordDeviceImpl extends AbstractAudioDeviceImpl implements RecordDevice {

    private ByteArrayOutputStream audioOutBuffer;

    public AudioRecordDeviceImpl() {
        super();
        audioOutBuffer = new ByteArrayOutputStream();
    }

    @Override
    protected void execute(byte[] audioInBuffer, int numberOfBytesRead) {
        audioOutBuffer.write(audioInBuffer, 0 , numberOfBytesRead);
    }

    @Override
    protected void closeResources() throws Exception {
        if (audioOutBuffer != null) {
            audioOutBuffer.close();
        }
    }

    public byte[] getData() {
        return audioOutBuffer.toByteArray();
    }
}
